package com.emokili.ewa.portal.controller;

import com.emokili.ewa.common.utils.R;
import com.emokili.ewa.common.vo.MemberRegisterVo;
import com.emokili.ewa.core.frame.service.MemberService;
import com.emokili.ewa.core.frame.vo.ProfileVo;
import com.emokili.ewa.core.frame.vo.UserCheckVo;
import com.emokili.ewa.portal.constant.Constants;
import com.emokili.ewa.portal.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    private MemberService memberService;
    @Autowired
    private UserService userService;

    @PostMapping("/exists/json")
    @ResponseBody
    public R exists(MemberRegisterVo memberRegisterVo){
        String email = memberRegisterVo.getEmail();
        String userName = memberRegisterVo.getUserName();
        if(Constants.USER_NAME.equals(userName)){
            memberService.checkEmailUnique(memberRegisterVo);
        }
        if(Constants.EMAIL.equals(email)){
            memberService.checkUserNameUnique(memberRegisterVo);
        }
        return R.ok();
    }

    @GetMapping("/profile/edit")
    public R profileEdit(){
        ProfileVo profile = userService.getProfile();
        return R.ok().setData(profile);
    }

}
